/*
 * Copyright (C) 2010-2011 Graz University of Technology, Austria. All Rights reserved. 
 *
 * Contact: Simone Kopeinik <simone.kopeinik@tugraz.at>
 * 	   Graz University of Technology, Knowledge Management Institute, Brückenkopfgasse 1/6, 8020 Graz 	
 * 	   <http://www.kmi.tugraz.at/>
 * 
 * This software is part of the TARGET platform developed by the
 * TARGET EC-funded project www.reachyourtarget.org
 *
 * This software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The GNU General Public License is available at <http://www.gnu.org/licenses/>.
 *
 */
package at.tugraz.kmi.css.cbkst2.prereq.structurevis;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.AbstractAction;
import javax.swing.Action;

import at.tugraz.kmi.css.cbkst2.CbKSTCompetence;
import at.tugraz.kmi.css.cbkst2.CbKSTVertex;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.jgoodies.binding.PresentationModel;

/**
 * Presentation Model for Competence Classes.
 * 
 * @author Georg Öttl
 */
@Singleton
public final class CompetenceModel extends PresentationModel<CbKSTVertex> {

	/**
	 * 
	 */
	private static final long		serialVersionUID	= 1L;

	private transient final Logger	log;

	/**
	 * A presentation model for an underlying competence domain object
	 * 
	 * @param vertex
	 *            The initial competence
	 * @param log
	 *            The logger to use
	 */
	@Inject
	public CompetenceModel(final CbKSTCompetence vertex, Logger log) {
		super(vertex);
		this.log = log;
		this.addBeanPropertyChangeListener(new BeanChannelChangeListener(
				this.log));
	}

	private static class BeanChannelChangeListener implements
			PropertyChangeListener {
		private final Logger	log;

		public BeanChannelChangeListener(Logger log) {
			this.log = log;
		}

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			log.log(Level.FINE, "Old Value = {0} , New Value = {1}",
					new Object[] { evt.getOldValue(), evt.getNewValue() });
		}
	}

	/**
	 * @return The apply Action for the Competence Model.
	 */
	public Action getApplyAction() {
		return new ApplyAction();
	}

	private class ApplyAction extends AbstractAction {

		/**
		 * 
		 */
		private static final long	serialVersionUID	= 1L;

		public ApplyAction() {
			super("Apply");
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			triggerCommit();
		}
	}
}
